package com.ruoyi.resume.controller;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.resume.domain.model.CandidateCompare;
import com.ruoyi.resume.domain.model.Job;
import com.ruoyi.resume.service.JobService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.ruoyi.common.utils.PageUtils.startPage;

@Api(tags = "岗位管理")
@RestController
@RequestMapping("/job")
public class JobController extends BaseController {

    @Autowired
    private JobService jobService;

    @ApiOperation(value = "显示所有岗位")
    @GetMapping("/all")
    @Anonymous
    public TableDataInfo getAllJobs(
            //@RequestParam(value = "start", defaultValue = "0") int start,
            //@RequestParam(value = "count", defaultValue = "10") int count
            ) {
        startPage();
        List<Job> jobs = jobService.getAllJobs();
        return getDataTable(jobs);
    }

    /**
     * 注意：该方法暂时不用，请用下方接口*/
    @ApiOperation(value = "初始化岗位候选人推荐信息(岗位导入或新增时调用)")
    @PutMapping("/initCandidates")
    @Anonymous
    public ResponseEntity<String> initCandidates() {
        jobService.initCandidates();
        return ResponseEntity.ok("初始化成功");
    }

    @ApiOperation(value = "更新单个岗位的候选人信息(岗位导入时调用,走AI)")
    @PutMapping("/updateCandidateAi/{jobId}")
    @Anonymous
    public ResponseEntity<String> updateCandidateViaAI(
            @PathVariable("jobId") int jobId) {
        boolean isUpdated = jobService.updateCandidateIdViaAi(jobId);
        if (isUpdated) {
            return ResponseEntity.ok("岗位候选人信息更新成功");
        } else {
            return ResponseEntity.status(400).body("更新失败");
        }
    }

    @ApiOperation(value = "更新所有岗位的候选人信息(简历新增时调用,不走AI)")
    @PutMapping("/updateAllCandidates")
    @Anonymous
    public ResponseEntity<String> updateAllCandidates() {
        boolean isUpdated = jobService.updateAllCandidateIds();
        if (isUpdated) {
            return ResponseEntity.ok("所有岗位候选人信息更新成功");
        } else {
            return ResponseEntity.status(400).body("更新失败");
        }
    }


    @ApiOperation(value = "更新单个岗位的候选人信息(简历新增时调用,不走AI)")
    @PutMapping("/updateCandidate/{jobId}")
    @Anonymous
    public ResponseEntity<String> updateCandidate(
            @PathVariable("jobId") int jobId) {
        boolean isUpdated = jobService.updateCandidateId(jobId);
        if (isUpdated) {
            return ResponseEntity.ok("岗位候选人信息更新成功");
        } else {
            return ResponseEntity.status(400).body("更新失败");
        }
    }

    /**
     * 候选人对比
     * @param Candidates:候选人id列表
     * @return 姓名/得分/岗位标签+(0-1标 识,是否拥有)
     * */
    @ApiOperation(value = "候选人对比")
    @PostMapping("/compareCandidates")
    @Anonymous
    public ResponseEntity<List<CandidateCompare>> compareCandidates(
            @RequestParam (value = "jobId") int jobId,
            @RequestBody List<Integer> Candidates) {
        List<CandidateCompare> result = jobService.compareCandidates(jobId,Candidates);
        return ResponseEntity.ok(result);
    }




//    @ApiOperation(value = "新增岗位")
//    @PostMapping("/add")
//    public ResponseEntity<String> addJob(@RequestBody Job job) {
//        jobService.addJob(job);
//        return ResponseEntity.ok("岗位新增成功");
//    }
//
//    @ApiOperation(value = "删除岗位")
//    @DeleteMapping("/delete/{jobId}")
//    public ResponseEntity<String> deleteJob(@PathVariable Integer jobId) {
//        jobService.deleteJob(jobId);
//        return ResponseEntity.ok("岗位删除成功");
//    }
//
//    @ApiOperation(value = "查询岗位")
//    @GetMapping("/get/{jobId}")
//    public ResponseEntity<Job> getJobById(@PathVariable Integer jobId) {
//        Job job = jobService.getJobById(jobId);
//        return ResponseEntity.ok(job);
//    }
//
//    @ApiOperation(value = "更新岗位")
//    @PutMapping("/update")
//    public ResponseEntity<String> updateJob(@RequestBody Job job) {
//        jobService.updateJob(job);
//        return ResponseEntity.ok("岗位更新成功");
//    }
}
